package com.cjz.demo1;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * lambda表达式之循环遍历
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("test");

        String[] strArr = {"abc", "def", "ghi"};
        List<String> strList = Arrays.asList(strArr);

        //传统方式遍历
        for (int i = 0, j = strList.size(); i < j; i++) {
            System.out.println(strList.get(i));
        }

        //foreach方式
        strList.forEach(new Consumer<String>() {
            @Override
            public void accept(String str) {
                System.out.println(str);
            }
        });

        //lambda表达式简化形式1
        strList.forEach((String str) -> System.out.println(str));

        //lambda表达式简化形式2
        strList.forEach((str) -> System.out.println(str));

        //lambda表达式简化形式3
        strList.forEach(str -> System.out.println(str));

        //lambda表达式此时所代表的:
        Consumer<String> consumer =  str -> System.out.println(str);
        strList.forEach(consumer);

        //方法索引
        strList.forEach(System.out::println);

    }
}
